//=============================================================================
// XBus 
//-----------------------------------------------------------------------------
// File        : daemon.c
// Description : 
// Author      : Ismail Sabry
// Date        : 1/30/2009
//=============================================================================
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

#include <xbus_interface.h>

//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
int get_option(int argc, char **argv, char *xbus_name, int *xbus_module )
{
  int ret=0;
  int c;
  
  opterr = 0;
  
  if(argc != 5) {
    ret = -1;
  } else {
    while ((c = getopt (argc, argv, "n:m:?")) != -1) {
      switch (c) {
      case 'n': 
	// xbus name
	snprintf(xbus_name, XBUS_SIZE_NAME-1, "%s", optarg);
	break;
      case 'm': 
	// nb modules
	*xbus_module = atoi(optarg);
	break;
      case '?':
      default :
	ret = -1;
	break;
      }
    }
  }
  
  if(ret != 0) {
    printf("\n");
    printf(" syntax: %s -n <name> -m <mid> \n", argv[0]);
    printf("    -n  xbus name\n");
    printf("    -m  module id\n");
    printf("    -?  this message \n");
    printf("\n");
  }

  return(ret);
}
